package cn.tedu.straw.portal.util;

import lombok.Data;
import lombok.experimental.Accessors;

import java.io.Serializable;

@Data
@Accessors(chain = true)
public class R<C> implements Serializable {
    private Integer state;
    private String message;
    private C data;

    public static R ok() {
        return new R().setState(State.OK);
    }

    public static R failure(Integer state, String message) {
        return new R().setState(state).setMessage(message);
    }

    public static R failure(Integer state, Throwable e) {
        return failure(state, e.getMessage());
    }

    public static <C> R<C> ok(C data){
        return R.ok().setData(data);
    }

    public interface State {
        Integer OK = 2000;
        Integer ERR_INSERT = 4000;
        Integer ERR_USERNAME_DUPLICATE = 4010;
    }
}
